package filecheck;

import java.io.*;

/**
 * Created by lawrence on 2015/9/21.
 */
public class FindString {
    public static void main(String[] a) {
        File fileFather = new File("E:\\WorkSpace\\companyWorkSpace\\CollectionAndMap");
        checkFile(fileFather);
        System.out.println("it is finished!");
    }


    public static void checkFile(File file) {
        int lineNumber = 0;
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File childFile : files) {
                checkFile(childFile);
            }
        } else {
            try {
                BufferedReader fis = new BufferedReader(
                        new InputStreamReader(new FileInputStream(file)));
                String line = fis.readLine();
                while (line != null) {
                    if (line.contains("annotation")) {
                        if (file.getName().contains(".java")) {
                            System.err.println(file.getName() + "    index =  " + lineNumber);
                        }
                    }
                    line = fis.readLine();
                    lineNumber++;
                }
                if (fis != null) {
                    fis.close();
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }

}
